package com.yanqu.road.server.cmd.marriage;

import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.logic.pb.MarriagePb;
import com.yanqu.road.pb.marriage.CrossMarriageProto;
import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.marriage.CrossUnionMarriageMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_MARRIAGE_GET_UNION_APPLY, desc = "获取跨服商会联姻")
public class CrossUnionMarriageGetApplyCmd extends CrossCommand {
    private long userId;
    private int childSex;
    private List<MarriageInfo> marriageInfoList;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossMarriageProto.CrossMarriageGetUnionApplyReqMsg reqMsg = CrossMarriageProto.CrossMarriageGetUnionApplyReqMsg.parseFrom(packet.getBytes());
        childSex = reqMsg.getChildSex();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        marriageInfoList = CrossUnionMarriageMgr.getUnionApplyList(userId, childSex);
    }

    @Override
    public void sendData() {
        MarriageProto.MarriageApplyListMsg.Builder respMsg = MarriagePb.parseMarriageApplyListMsg(marriageInfoList);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_MARRIAGE_GET_SERVER_APPLY_LIST, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }
}
